@extends('public.dashboard_base')
@section('title', '在线充值')
@section('content')
    <div class="control_panel_content">
        <div class="navBreadcrumb">
            <ul>
                <li>资金管理</li>
                <li><a href="/funds/recharge">在线充值</a></li>
            </ul>
        </div>
        <div class="panel">
            <div class="sub_nav_container">
                <ul class="clearfix">
                    <li class="active"><a href="javascript:;">在线充值</a></li>
                    <li><a href="/funds/list">资金明细</a></li>
                </ul>
            </div>
            <style>
                .recharge_away_switch li {
                    display: inline-block !important;
                    margin-right: 20px;
                }

                .recharge_away_switch li img {
                    width: 50%;
                }
            </style>
            <div class="panel_body">
                <form id="recharge_form" action="/funds/recharge" method="post">
                    <ul class="form_group">
                        <li>
                            <span class="form_label">充值方式</span>
                            <ol class="recharge_away_switch">
                                <li class="zfb active"><img src="/static/image/zfb.png" width="90" alt=""><span
                                            class="icon"><i class="iconfont iconcheck"></i></span></li>
                                {{--                                <li class="wx"><img src="/common/images/pay_11.png" width="90" alt=""><span class="icon"><i class="iconfont iconcheck"></i></span></li>--}}
                            </ol>
                        </li>
                        <li>
                            <span class="form_label">充值金额</span>
                            <input type="number" name="money" id="cz-money">&ensp;
                            <span>最小金额10元</span>
                        </li>
                        {{--                         <li>--}}
                        {{--                             <span class="form_label"></span>--}}
                        {{--                             <span class="text_orange">注：当月单笔充值满1000元，当月可以享受<a--}}
                        {{--                                     href="https://www.17ex.com/notice/detail?id=39"--}}
                        {{--                                     target="_blank">竞价优惠政策</a></span>--}}
                        {{--                         </li>--}}
                        <li>
                            <span class="form_label">&nbsp;</span>
                            <input type="button" class="btn btn_primary clearSingle" value="充值">
                        </li>
                    </ul>
                </form>
            </div>
        </div>
    </div>
@endsection
@section('script')
    <script>
        $(function () {
            var link = $("#funds-recharge");
            link.parent().parent().parent().addClass("active");
            link.parent().addClass("active");
        });


        // 匹配正确输入金额
        function howMuch(val) {
            //  var pattern = /^([1-9][0-9]*(.\d{1,2})?)$/;
            var pattern = /^([1-9][0-9]*?)$/;
            if (!pattern.test(val) || val < 10) {
                return true;
            }
            return false;
        }

        // 充值
        $(".clearSingle").click(function () {
            var money = $('#cz-money').val();
            if (howMuch(money)) {
                layer.msg('请输入正确的金额!', {icon: 2, time: 1000});
                return;
            }
            if ($(".zfb").attr('class') === 'zfb active') {
                var type = 1;
            } else {
                type = 2;
            }
            $.ajax({
                url: '/funds/recharge',
                //dataType: 'json',
                type: 'post',
                data: {'_token': '{{csrf_token()}}', 'money': money, 'paytype': type},
                success: function (data) {
                    if (data.msg === 'success') {
                        window.location.href = '/pay/alipay?outTradeNo=' + data.data.outTradeNo + '&type=wap'
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                }
            })
        });

        $(".zfb").click(function () {
            $(".zfb").attr('class', 'zfb active');
            $(".wx").attr('class', 'wx');
        })
        $(".wx").click(function () {
            $(".zfb").attr('class', 'zfb');
            $(".wx").attr('class', 'wx active');
        })
    </script>
@endsection
